package com.ice.base.controller;

import com.github.pagehelper.PageHelper;
import com.ice.base.model.SysLoginLogModel;
import com.ice.base.result.AjaxResult;
import com.ice.base.result.ResponseResult;
import com.ice.base.service.SysLoginLogService;
import com.ice.body.business.model.FaceLogModel;
import com.ice.body.hardware.service.FaceLogService;
import com.ice.body.rpc.dto.WeighLog;
import com.ice.body.rpc.service.WeighLogService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@ApiIgnore(value = "系统后台-登录日志")
public class SysLoginLogController extends BaseController{

    @Resource
    private SysLoginLogService sysLoginLogService;
    @Resource
    private WeighLogService weighLogService;


    @ApiIgnore(value = "菜单-查询分页")
    @PostMapping("/sysLoginLog/selectListByPageHelper")
    public AjaxResult<SysLoginLogModel> selectListByPageHelper(HttpServletRequest request,
                                                               @RequestParam(name = "pageSize") Integer pageSize,
                                                               @RequestParam(name = "pageNum") Integer pageNum) {

        AjaxResult r = ResponseResult.success();
        ArrayList list;
        SysLoginLogModel log =  new SysLoginLogModel();
       /*  SysLoginModel currLoginModel = BaseUtil.getCurrLoginModel();
       if(!"admin".equals(currLoginModel.getUserName())){
            model.setCompanyId(currLoginModel.getCompanyId());
        }*/
        try{
            PageHelper.startPage(pageNum, pageSize);
            list = sysLoginLogService.selectListByModel(log);

            getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }




    @ApiIgnore(value = "记录-称重")
    @PostMapping("/api/WeighLog/selectListByPageHelper")
    public AjaxResult<WeighLog> selectWeighLog(HttpServletRequest request,
                                                  @RequestParam(name = "pageSize") Integer pageSize,
                                                  @RequestParam(name = "pageNum") Integer pageNum) {

        AjaxResult r = AjaxResult.success();
        List list;
        try{
            PageHelper.startPage(pageNum, pageSize);
            list = weighLogService.selectListByModel(new WeighLog());
            getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }


}
